package net.mcreator.makecustomitem.procedure;

import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.eventhandler.Event;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.event.entity.player.ItemTooltipEvent;
import net.minecraftforge.common.MinecraftForge;

import net.minecraft.world.World;
import net.minecraft.util.text.TextComponentTranslation;
import net.minecraft.item.ItemStack;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.client.util.ITooltipFlag;

import net.mcreator.makecustomitem.ElementsMakecustomitemMod;

import java.util.Map;
import java.util.List;
import java.util.HashMap;

@ElementsMakecustomitemMod.ModElement.Tag
public class ProcedureItemLore extends ElementsMakecustomitemMod.ModElement {
	public ProcedureItemLore(ElementsMakecustomitemMod instance) {
		super(instance, 4);
	}

	public static void executeProcedure(Map<String, Object> dependencies) {
		if (dependencies.get("itemstack") == null) {
			System.err.println("Failed to load dependency itemstack for procedure ItemLore!");
			return;
		}
		if (dependencies.get("tooltip") == null) {
			System.err.println("Failed to load dependency tooltip for procedure ItemLore!");
			return;
		}
		ItemStack itemstack = (ItemStack) dependencies.get("itemstack");
		Object tooltip = (Object) dependencies.get("tooltip");
		if (dependencies.get("event") != null) {
			Object _obj = dependencies.get("event");
			if (_obj instanceof Event) {
				Event _evt = (Event) _obj;
				ItemTooltipEvent _event = (ItemTooltipEvent) _evt;
				if ((((itemstack).hasTagCompound() ? (itemstack).getTagCompound().getDouble("Attack") : -1) > 0)) {
					_event.getToolTip().add(1,
							(((new TextComponentTranslation("Attack").getUnformattedComponentText())) + "" + ((new java.text.DecimalFormat("0")
									.format(((itemstack).hasTagCompound() ? (itemstack).getTagCompound().getDouble("Attack") : -1))))));
				}
				if ((((itemstack).hasTagCompound() ? (itemstack).getTagCompound().getDouble("Defense") : -1) > 0)) {
					_event.getToolTip().add(1,
							(((new TextComponentTranslation("Defense").getUnformattedComponentText())) + "" + ((new java.text.DecimalFormat("0")
									.format(((itemstack).hasTagCompound() ? (itemstack).getTagCompound().getDouble("Defense") : -1))))));
				}
				if ((((itemstack).hasTagCompound() ? (itemstack).getTagCompound().getDouble("Speed") : -1) > 0)) {
					_event.getToolTip().add(1,
							(((new TextComponentTranslation("Speed").getUnformattedComponentText())) + "" + ((new java.text.DecimalFormat("0")
									.format(((itemstack).hasTagCompound() ? (itemstack).getTagCompound().getDouble("Speed") : -1))))));
				}
				if ((((itemstack).hasTagCompound() ? (itemstack).getTagCompound().getDouble("Regen") : -1) > 0)) {
					_event.getToolTip().add(1,
							(((new TextComponentTranslation("Regen").getUnformattedComponentText())) + "" + ((new java.text.DecimalFormat("0")
									.format(((itemstack).hasTagCompound() ? (itemstack).getTagCompound().getDouble("Regen") : -1))))));
				}
				if ((((itemstack).hasTagCompound() ? (itemstack).getTagCompound().getDouble("Health") : -1) > 0)) {
					_event.getToolTip().add(1,
							(((new TextComponentTranslation("Health").getUnformattedComponentText())) + "" + ((new java.text.DecimalFormat("0")
									.format(((itemstack).hasTagCompound() ? (itemstack).getTagCompound().getDouble("Health") : -1))))));
				}
				if ((((itemstack).hasTagCompound() ? (itemstack).getTagCompound().getDouble("Assassination") : -1) > 0)) {
					_event.getToolTip().add(1,
							(((new TextComponentTranslation("Assassination").getUnformattedComponentText())) + "" + ((new java.text.DecimalFormat("0")
									.format(((itemstack).hasTagCompound() ? (itemstack).getTagCompound().getDouble("Assassination") : -1))))));
				}
			}
		}
	}

	@SubscribeEvent
	public void onItemTooltip(ItemTooltipEvent event) {
		if (event != null && event.getEntityPlayer() != null) {
			EntityPlayer entity = event.getEntityPlayer();
			ItemStack itemStack = event.getItemStack();
			List<String> tooltip = event.getToolTip();
			ITooltipFlag flag = event.getFlags();
			World world = entity.world;
			double i = entity.posX;
			double j = entity.posY;
			double k = entity.posZ;
			Map<String, Object> dependencies = new HashMap<>();
			dependencies.put("x", i);
			dependencies.put("y", j);
			dependencies.put("z", k);
			dependencies.put("world", world);
			dependencies.put("entity", entity);
			dependencies.put("itemstack", itemStack);
			dependencies.put("flag", flag);
			dependencies.put("tooltip", tooltip);
			dependencies.put("event", event);
			this.executeProcedure(dependencies);
		}
	}

	@Override
	public void preInit(FMLPreInitializationEvent event) {
		MinecraftForge.EVENT_BUS.register(this);
	}
}
